﻿using DA6502.Controls;

namespace DA6502.CPU
{

    public partial class CPU
    {

        public byte DisassemblySingleStep()
        {
            ushort curpc = PC;  //  IF()会改变PC的值，所以记录一下以便稍后显示汇编指令

            currOpNum = string.Empty;

            byte cmd = IF();
            Execute(cmd);
            int len = CommandDictionary.CommandCodes[cmd].Length;



            IO.SetInstruction(curpc, CommandDictionary.CommandCodes[cmd].Command + " " + currOpNum);
            IO.SetLength(curpc, CommandDictionary.CommandCodes[cmd].Length);
            IO.SetCellType(curpc, CELL_TYPE.INSTRUCTION);

            if (len == 2)
            {
                IO.SetCellType((ushort)(curpc + 1), CELL_TYPE.OPERATOR);
            }
            else if (len == 3)
            {
                IO.SetCellType((ushort)(curpc + 1), CELL_TYPE.OPERATOR);
                IO.SetCellType((ushort)(curpc + 2), CELL_TYPE.OPERATOR);
            }

            IO.Dirty = true;
            return cmd;
        }
    }
}